﻿using System;
using System.Collections.Generic;
using System.Text;

namespace Xylee.Common.Modules
{
    /// <summary>
    /// A module is an installation that contains 
    /// more than one portal view. Each portal 
    /// is defined and referenced with a qulified 
    /// name using the full namespace and class name.
    /// The module is identified by it's qualifying 
    /// xylee module installation name or Xym name.
    /// Identifying the module is done so by 
    /// it's key, such as it's location on the web, 
    /// and the value done so by it's xym name.
    /// <remarks>Implement this class by loading 
    /// a module assembly into memory and referencing 
    /// the portals according to the available modules 
    /// and portals in the main application class.</remarks>
    /// </summary>
    public class Module
    {
        private string qName;
        private string version;
        private string uri;
        private IList<string> modulePortals;

        public Module(string qName, string version, string uri)
        {
            this.qName = qName;
            this.version = version;
            this.uri = uri;
            this.modulePortals = new List<string>();
        }

        /// <summary>
        /// Attempts to add a portal type to the list of 
        /// module portals. Use the typeof if you have an object 
        /// or explicit type attribute.
        /// </summary>
        /// <param name="portalType"><seealso cref="portalUri"/> of IPortal implementation</param>
        /// <returns>True if the portal was added, false otherwise.</returns>
        public bool AddPortal(string portalUri)
        {
            if (!this.modulePortals.Contains(portalUri))
            {
                this.modulePortals.Add(portalUri);
                return true;
            }

            return false;
        }

        public IList<string> Portals
        {
            get { return this.modulePortals; }
        }

        public string QualifiedName
        {
            get { return this.qName; }
            set { this.qName = value; }
        }

        public string Version
        {
            get { return this.version; }
            set { this.version = value; }
        }

        public string Uri
        {
            get { return this.uri; }
            set { this.uri = value; }
        }
    }
}
